//
//  BRCrossingModel.m
//  百思不得姐
//
//  Created by LinBrong on 16/8/24.
//  Copyright © 2016年 LinBrong. All rights reserved.
//

#import "BRCrossingModel.h"
#import "NetWorkTool.h"

@implementation BRCrossingModel

-(void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

+(instancetype)crossingModelWithDict:(NSDictionary *)dict{
    BRCrossingModel *model = [[BRCrossingModel alloc]init];
    [model setValuesForKeysWithDictionary:dict];
    [model setValue:dict[@"id"] forKey:@"ID"];
    return model;
}

+ (void)downloadWithURLStr:(NSString *)urlStr successBlock:(void(^)(NSArray *Array))successBlock failBlock:(void(^)(NSError *error))failBlock {

    NetWorkTool *tool = [NetWorkTool defaultNetWorkTool];
    
    
    
    [tool GET:urlStr parameters:nil progress:nil
     success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         
        NSDictionary *dict = responseObject;
        
//         NSDictionary *infoDict = dict[@"info"];
         
         NSArray *listArr = dict[@"list"];
         
         NSMutableArray *tempArr = [NSMutableArray arrayWithCapacity:listArr.count];
         [listArr enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
             
             BRCrossingModel *model = [BRCrossingModel crossingModelWithDict:obj];
             [tempArr addObject:model];
             
         }];
         
         if(successBlock){
             
             successBlock(tempArr.copy);
             
         }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if(failBlock) {
            failBlock(error);
        }
        
    }];

}

/*  "info":{
 "count":"79",
 "page":4,
 "maxid":1410190082,
 "maxtime":1410190082
 },*/
@end
